/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 主题变量系统 */
:root {
  /* 基础主题变量 */
  --theme-primary: #4361ee;
  --theme-primary-light: #7209b7;
  --theme-primary-dark: #3a0ca3;
  --theme-secondary: #4cc9f0;
  --theme-background: #f8f9fa;
  --theme-surface: #ffffff;
  --theme-text-primary: #212529;
  --theme-text-secondary: #6c757d;
  --theme-text-tertiary: #adb5bd;
  --theme-border: #e9ecef;
  --theme-error: #e63946;
  --theme-success: #4cc9f0;
  --theme-warning: #ffb703;
  --theme-info: #4895ef;

  /* 聊天界面特定变量 */
  --bg-primary: #f8f9fa;
  --bg-secondary: #e9ecef;
  --border-color: #dee2e6;
  --message-bg-user: #4361ee;
  --message-bg-bot: #f8f9fa;
  --message-text-user: #ffffff;
  --message-text-bot: #212529;
  --message-border-radius: 18px;
  --scrollbar-track: #f1f1f1;
  --scrollbar-thumb: #c1c1c1;
  --scrollbar-thumb-hover: #a8a8a8;

  /* 字体配置 */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  
  /* 间距配置 */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-xxl: 48px;
  
  /* 边框圆角 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* 阴影效果 */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* 过渡动画 */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* 暗色主题 */
[data-theme="dark"] {
  --theme-primary: #7209b7;
  --theme-primary-light: #f72585;
  --theme-primary-dark: #3a0ca3;
  --theme-secondary: #4361ee;
  --theme-background: #121212;
  --theme-surface: #1e1e1e;
  --theme-text-primary: #ffffff;
  --theme-text-secondary: #b0b0b0;
  --theme-text-tertiary: #707070;
  --theme-border: #333333;
  --theme-error: #f72585;
  --theme-success: #4cc9f0;
  --theme-warning: #ffb703;
  --theme-info: #4895ef;
  
  /* 聊天界面特定变量 */
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --border-color: #333333;
  --message-bg-user: #7209b7;
  --message-bg-bot: #2d2d2d;
  --message-text-user: #ffffff;
  --message-text-bot: #e0e0e0;
  --scrollbar-track: #2d2d2d;
  --scrollbar-thumb: #555555;
  --scrollbar-thumb-hover: #777777;
}

/* 基础样式 */
body {
  font-family: var(--font-family);
  background-color: var(--theme-background);
  color: var(--theme-text-primary);
  line-height: 1.6;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* 滚动条美化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* 按钮基础样式 */
button {
  font-family: inherit;
  font-size: 14px;
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  border-radius: var(--radius-md);
  background-color: var(--theme-primary);
  color: white;
  cursor: pointer;
  transition: all var(--transition-normal);
  outline: none;
}

/* 按钮基础样式 */
button {
  font-family: inherit;
  font-size: 14px;
  padding: var(--spacing-sm) var(--spacing-md);
  border: none;
  border-radius: var(--radius-md);
  background-color: var(--theme-primary);
  color: white;
  cursor: pointer;
  transition: all var(--transition-normal);
  outline: none;
}

button:hover {
  background-color: var(--theme-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  background-color: var(--theme-text-tertiary);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 特定元素的调整 */
#clear-all-history-button,
.clear-all-history-button {
  color: #ef4444;
  background-color: transparent;
  border: none;
  width: 100%;
  text-align: center;
  padding: var(--spacing-sm) 0;
  margin-top: var(--spacing-md);
}

[id^="history-item-"] {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  width: 100% !important;
  padding: 8px !important;
}

/* 历史记录相关按钮样式 */
#history-button,
#clear-history-button,
#close-history-button,
[id^="history-item-"] button,
[id^="remove-history-"] button,
#clear-all-history-button,
.history-button,
.clear-history-button,
.close-history-button,
.history-item button,
.remove-history-button,
.clear-all-history-button {
  background-color: transparent;
  color: var(--theme-text-primary);
  border: none;
  padding: var(--spacing-xs) var(--spacing-sm);
  transition: all var(--transition-normal);
  outline: none;
  box-shadow: none;
}

/* 确保按钮在所有状态下都没有边框 */
#history-button:focus,
#clear-history-button:focus,
#close-history-button:focus,
[id^="history-item-"] button:focus,
[id^="remove-history-"] button:focus,
#clear-all-history-button:focus,
.history-button:focus,
.clear-history-button:focus,
.close-history-button:focus,
.history-item button:focus,
.remove-history-button:focus,
.clear-all-history-button:focus {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}

/* 历史记录相关按钮悬停效果 */
#history-button:hover,
#clear-history-button:hover,
#close-history-button:hover,
[id^="history-item-"] button:hover,
[id^="remove-history-"] button:hover,
#clear-all-history-button:hover,
.history-button:hover,
.clear-history-button:hover,
.close-history-button:hover,
.history-item button:hover,
.remove-history-button:hover,
.clear-all-history-button:hover {
  text-decoration: underline;
  background-color: var(--theme-background);
}

/* 历史记录相关按钮点击效果 */
#history-button:active,
#clear-history-button:active,
#close-history-button:active,
[id^="history-item-"] button:active,
[id^="remove-history-"] button:active,
#clear-all-history-button:active,
.history-button:active,
.clear-history-button:active,
.close-history-button:active,
.history-item button:active,
.remove-history-button:active,
.clear-all-history-button:active {
  background-color: var(--theme-primary-light);
}

/* 输入框基础样式 */
input, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--theme-border);
  border-radius: var(--radius-md);
  background-color: var(--theme-surface);
  color: var(--theme-text-primary);
  transition: all var(--transition-normal);
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--theme-border);
  box-shadow: none;
}

/* 卡片样式 */
.card {
  background-color: var(--theme-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--spacing-lg);
  transition: all var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

/* 标题样式 */
h1, h2, h3, h4, h5, h6 {
  color: var(--theme-text-primary);
  margin-bottom: var(--spacing-md);
  font-weight: 600;
  line-height: 1.2;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

h4 {
  font-size: 1.125rem;
}

h5, h6 {
  font-size: 1rem;
}

/* 链接样式 */
a {
  color: var(--theme-primary);
  text-decoration: none;
  transition: color var(--transition-normal);
}

a:hover {
  color: var(--theme-primary-dark);
  text-decoration: underline;
}

/* 工具类 */
.flex {
  display: flex;
}

.flex-column {
  flex-direction: column;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-wrap {
  flex-wrap: wrap;
}

.gap-xs {
  gap: var(--spacing-xs);
}

.gap-sm {
  gap: var(--spacing-sm);
}

.gap-md {
  gap: var(--spacing-md);
}

.gap-lg {
  gap: var(--spacing-lg);
}

.gap-xl {
  gap: var(--spacing-xl);
}

.mt-xs {
  margin-top: var(--spacing-xs);
}

.mt-sm {
  margin-top: var(--spacing-sm);
}

.mt-md {
  margin-top: var(--spacing-md);
}

.mt-lg {
  margin-top: var(--spacing-lg);
}

.mt-xl {
  margin-top: var(--spacing-xl);
}

.mb-xs {
  margin-bottom: var(--spacing-xs);
}

.mb-sm {
  margin-bottom: var(--spacing-sm);
}

.mb-md {
  margin-bottom: var(--spacing-md);
}

.mb-lg {
  margin-bottom: var(--spacing-lg);
}

.mb-xl {
  margin-bottom: var(--spacing-xl);
}

.p-xs {
  padding: var(--spacing-xs);
}

.p-sm {
  padding: var(--spacing-sm);
}

.p-md {
  padding: var(--spacing-md);
}

.p-lg {
  padding: var(--spacing-lg);
}

.p-xl {
  padding: var(--spacing-xl);
}

.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.text-primary {
  color: var(--theme-text-primary);
}

.text-secondary {
  color: var(--theme-text-secondary);
}

.text-tertiary {
  color: var(--theme-text-tertiary);
}

.text-error {
  color: var(--theme-error);
}

.text-success {
  color: var(--theme-success);
}

.text-warning {
  color: var(--theme-warning);
}

.text-info {
  color: var(--theme-info);
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 角色信息样式 */
.selected-user-name,
.selected-user-title,
.role-description,
.history-title {
  color: var(--theme-text-primary);
}

.selected-user-name {
  font-weight: 600;
}

.selected-user-title {
  font-weight: 500;
}

.role-description {
  font-weight: 400;
}

.history-title {
  font-weight: 600;
  font-size: 1.2rem;
}

/* 快速对话按钮样式 */
.quick-message-button {
  color: white;
  background-color: var(--theme-primary);
  font-weight: 500;
}

@keyframes slideInUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInDown {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInLeft {
  from {
    transform: translateX(-20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 动画工具类 */
.animate-fade-in {
  animation: fadeIn var(--transition-normal) ease-out;
}

.animate-slide-in-up {
  animation: slideInUp var(--transition-normal) ease-out;
}

.animate-slide-in-down {
  animation: slideInDown var(--transition-normal) ease-out;
}

.animate-slide-in-left {
  animation: slideInLeft var(--transition-normal) ease-out;
}

.animate-slide-in-right {
  animation: slideInRight var(--transition-normal) ease-out;
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* 响应式设计 */
@media (max-width: 768px) {
  :root {
    --spacing-lg: 16px;
    --spacing-xl: 24px;
    --spacing-xxl: 32px;
  }
  
  h1 {
    font-size: 1.75rem;
  }
  
  h2 {
    font-size: 1.25rem;
  }
  
  h3 {
    font-size: 1.125rem;
  }
}

@media (max-width: 480px) {
  :root {
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 20px;
  }
  
  h1 {
    font-size: 1.5rem;
  }
  
  button, input, textarea {
    font-size: 16px; /* 防止iOS缩放 */
  }
}